#!/usr/bin/env python
#coding=utf-8
import sys
import os
sys.path.insert(0, os.path.join(os.getcwd(), 'contrib'))

import web
import utils
#import models
import admin
import tublog

urls = ('/', 'tublog.Home',
        '/(\d+)', 'tublog.Home',
        '/rss', 'tublog.RssViewer',
        '/tag/(.*)/(\d+)', 'tublog.TagViewer',
        '/tag/(.*)', 'tublog.TagViewer',
        '/view/(\d+)', 'tublog.EntryViewer',
        '/admin', 'admin.Home',
        '/admin/entry', 'admin.EntryManager',
        '/admin/entry/(\d+)', 'admin.EntryManager',
        '/admin/entry/(new)', 'admin.EntryEditor',
        '/admin/entry/(edit)/(\d+)', 'admin.EntryEditor',
        '/admin/comment','admin.CommentManager',
        '/admin/comment/(\d+)','admin.CommentManager',
        '/admin/pref','admin.PrefEditor',
        '/admin/widget', 'admin.WidgetManager',
        '/admin/widget/(.*)/(.*)', 'admin.WidgetManager',
        '/admin/apipass', 'admin.RpcManager',
        '/admin/update', 'admin.Updater',
        '/admin/test', 'admin.Test',
        '/xmlrpc', 'admin.RpcHandler',
        )

#env = {}


def notfound():
    return web.notfound(utils.render_theme('404.html', vars=dict(title='Not Found', path=web.ctx.path)))


def main():
    #global env
    #env['get_blog_config'] = models.get_blog_config

    application = web.application(urls, globals())
    #application.notfound = notfound
    application.cgirun()


if __name__ == "__main__":
    main()
